<template>
  <div class="bottom-container borderStyle">
    <div class="blueTitleStyle betweenbox">
      <span>历史告警信息</span>
      <span class="detail centerbox" @click="toDetail">详情</span>
    </div>
    <div
      class="bottom-table mediumtablestyle"
      v-loading="loading"
      element-loading-text="数据加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(0, 0, 0, 0.8)"
    >
      <el-table
        :data="tableDataList"
        :row-class-name="tableRowClassName"
        style="width: 100%"
        border
        height="100%"
      >
        <el-table-column prop="BDZMC" label="变电站名称" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="SJMS" :show-overflow-tooltip="true" label="事件描述"></el-table-column>
        <el-table-column prop="KSSJ" :show-overflow-tooltip="true" label="发生时间">
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="图像/录像">
          <template slot-scope="scope">
            <viewer :images="[scope.row.IMAGEURL]" @inited="inited(scope.row,$event)">
              <img :src="scope.row.IMAGEURL" alt srcset v-show="false" />
              <span class="iconfont iconpicture pitcure" @click="clickEvent(scope.row)"></span>
            </viewer>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-dialog title="历史信息" :visible.sync="visible" width="80%">
      <Detail />
      <iframe class="iframe" frameborder=0></iframe>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import Detail from "../Detail/index.vue";
@Component({
  components: { Detail },

})
export default class extends Vue {
  loading: boolean = false;
  visible: boolean = false;
  tableDataList: Array<any> = [];
  // 表格隔行变色
  tableRowClassName(row: object, rowIndex: number): string {
    if (rowIndex % 2 === 0) {
      return "row1";
    } else {
      return "row2";
    }
  }
  mounted() {
    this.queryHistoryAlarmInfo();
  }
  // 显示详情信息
  toDetail() {
    this.visible = true;
  }
  // 初始化图片放大
  inited(row, viewer) {
    row.viewer = viewer;
  }
  addInframe() {
    // let el-picker-panel el-date-picker el-popper
    window.setTimeout(() => {
      let pickerArr = document.querySelectorAll(".viewer-container");
      pickerArr.forEach((item) => {
        let width = item.clientWidth;
        let height = item.clientHeight;
        let iframe: any = item.querySelector("iframe");
        if (!iframe) {
          iframe = document.createElement("iframe");
          item.appendChild(iframe);
        }
        iframe.style.width = width + "px";
        iframe.style.height = height + "px";
        iframe.style.position = "absolute";
        iframe.style.top = "0px";
        iframe.style.left = "0px";
        iframe.style.zIndex = 1;
        iframe.style.zIndex = 1;
        iframe.style.pointerEvents = "none";
      });
    }, 100);
  }
  // 获取数据
  queryHistoryAlarmInfo() {
    this.loading = true;
    let data = { rows: 10 };
    (this as any).$services
      .queryHistoryAlarmInfo({ data })
      .then((result: any) => {
        this.loading = false;
        this.tableDataList = result.data.map(v=>{
          if (v.KSSJ) {
          v.KSSJ=v.KSSJ.slice(0,10) +v.KSSJ.slice(11,19)
            
          }
          return v
        });
      })
      .catch((err: object) => {
        this.loading = false;
        console.log(err);
      });
  }
  // 录制/图像点击事件
  clickEvent(row: any) {
    row.viewer.show();
    this.addInframe()
  }
}
</script>

<style lang="scss" scoped>
.bottom-container {
  width: 100%;
  height: 100%;
  .detail {
    border: 1px solid rgba(5, 180, 255, 1);
    // margin: 0.03rem 0.1rem 0rem 0rem;
    width: 0.8rem;
    height: 0.24rem;
    font-size: 0.16rem;
    border-radius: 0.02rem;
    cursor: pointer;
  }
  .bottom-table {
    width: 100%;
    height: calc(100% - 0.4rem);
    margin: 0.1rem auto;
    padding: 0.1rem;
    .pitcure {
      font-size: 0.24rem;
      cursor: pointer;
    }
  }
  .iframe {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0px;
    left: 0px;
    z-index: 1;
    opacity: 0.1;
    background: none;
    pointer-events: none;
  }
}
</style>

